<template>
  <div class="app-container">
    <div class="servers initializeRoll">
      <div class="title">
        <img src="../../../assets/images/wtb4.png" alt />
        <span>租户管理</span>
      </div>
      <!-- <p class="borderBox"></p> -->
      <div class="sousuoBox">
        <el-form
          :model="queryParams"
          ref="queryForm"
          v-show="showSearch"
          :inline="true"
        >
         <el-form-item label="日期范围" prop="field103">
              <el-date-picker
             
                type="daterange"
                v-model="queryParams.cTime"
                format="yyyy-MM-dd"
                value-format="yyyy-MM-dd"
               style="width:200px"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                range-separator="至"
                clearable
              ></el-date-picker>
            </el-form-item>
          <el-form-item label="租户名称">
            <el-input
              style="width:200px"
              maxlength="32"
              v-model.trim="queryParams.nickName"
              placeholder="输入租户名称"
              clearable
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>


            <el-form-item
                label="权限模板名称"
                prop="field105"
              >
                <el-select
                  v-model="queryParams.tempName"
                  placeholder="请选择权限模板名称"
                  clearable
                 style="width:200px"
                >
                  <el-option
                    v-for="(item, index) in AuthorityData"
                    :key="index"
                    :label="item.name"
                    :value="item.id"
                    :disabled="item.disabled"
                  ></el-option>
                </el-select>
              </el-form-item>



         
          <el-form-item label="手机号">
            <el-input
              style="width:200px"
              maxlength="11"
              clearable
              v-model.trim="queryParams.phoneNumber"
              placeholder="输入手机号"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="状态" prop="field101">
            <el-select
              v-model="queryParams.stateUser"
              placeholder="请选择类型"
              clearable
             style="width:200px"
            >
              <el-option
                v-for="(item, index) in field101Options"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="getList"
              >搜索</el-button
            >
            <!-- <el-button
          size="small"
          type="primary"
          icon="el-icon-plus"
          @click="addVisible = true"
          >添加</el-button
        > -->
          </el-form-item>
        </el-form>
      </div>

      <el-row :gutter="10" class="mb8" style="margin-top:10px">
        <el-col :span="1.5">
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="addData"
            >新增</el-button
          >
        </el-col>
        <el-col :span="1.5">
          <!-- <el-button
            size="mini"
            type="primary"
            round
            icon="el-icon-download"
            :loading="exportLoading"
            @click="handleExport"
            v-hasPermi="['system:role:export']"
            >导出</el-button
          > -->
        </el-col>
      </el-row>

      <!-- <el-table
        v-loading="loading"
        :data="roleList"
        @selection-change="handleSelectionChange"
      > -->
       <el-table :data="roleList" style="width: 100%" height="400">
        <el-table-column label="编号" align="center" prop="userId" />
        <el-table-column
          label="租户名称"
          prop="nickName"
          :show-overflow-tooltip="true"
          width="150"
          align="center"
        />
        <el-table-column
          label="账号"
          prop="userName"
          align="center"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column label="手机号" align="center" prop="phoneNumber" />
        <el-table-column label="状态" align="center" prop="stateUser">
          <template slot-scope="scope">
            <span v-show="scope.row.stateUser == 0">正常</span>
            <span v-show="scope.row.stateUser == 1">停用</span>
            <span v-show="scope.row.stateUser == 2">禁用</span>
          </template>
        </el-table-column>

        <el-table-column label="创建时间" prop="ccTime" align="center" />

        <el-table-column label="到期时间" prop="eTime" align="center" />
        <el-table-column label="可创建项目个数" prop="proNum" align="center" />
        <el-table-column label="权限模板名称" prop="tempName" align="center" />
        <!-- <el-table-column label="身份证号" prop="idCard" align="center">
            <template slot-scope="scope">
            <span>{{scope.row.idCard||'暂无'}}</span>
          </template>
          </el-table-column> -->
        <el-table-column align="center" label="操作">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="handleEdit(scope.$index, scope.row)"
              style="text-decoration:underline"
              >编辑</el-button
            >
            <!-- <el-popconfirm
              title="确定删除吗？"
              @confirm="deleteUser(scope.$index, scope.row)"
              style="margin-left: 10px"
            > -->
            <!-- <el-button
                slot="reference"
                confirm
                size="mini"
                type="text"
                icon="el-icon-delete"
                >删除</el-button
              > -->
            <!-- </el-popconfirm> -->
          </template>
        </el-table-column>
      </el-table>


      <pagination
        :total="total"
        style="margin:40px 0px 40px 0px"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />

      <!-- ..编辑弹窗 -->
      <el-dialog
        title="编辑"
        :visible.sync="editFormVisible"
        width="30%"
      
      >
        <el-form
          label-width="150px"
          :model="revise"
          :rules="reviseRules"
          ref="ruleForm"
        >
          <el-form-item label="租户名称" prop="nickName">
            <el-input
              size="small"
              v-model="revise.nickName"
              auto-complete="off"
              maxlength="10"
              placeholder="请输入租户名称"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="账号" prop="userName">
            <el-input
              size="small"
              maxlength="20"
              v-model="revise.userName"
              auto-complete="off"
              placeholder="请输入账号"
               disabled
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="手机号" prop="phonenumber">
            <el-input
              size="small"
              maxlength="11"
              v-model.number="revise.phonenumber"
              auto-complete="off"
              placeholder="请输入手机号"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="可创建项目个数" prop="proNum">
            <el-input
              size="small"
              maxlength="3"
              v-model.number="revise.proNum"
              auto-complete="off"
              placeholder="请输入可创建项目个数"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="到期时间" prop="expirationTime">
            <el-date-picker
              v-model="revise.expirationTime"
              type="date"
              placeholder="选择日期"
              :picker-options="pickerOptions0"
            >
            </el-date-picker>
          </el-form-item>


              <el-form-item label="权限模板" prop="Authority">
             <el-select
                      v-model="revise.Authority"
                      placeholder="请输入权限模板"
                      clearable
                      :style="{ width: '100%' }"
                    >
                      <el-option
                        v-for="(item, index) in AuthorityData"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                        :disabled="item.disabled"
                      ></el-option>
                    </el-select>
          </el-form-item>
              <el-form-item label="状态" prop="state">
             <el-select
                      v-model="revise.state"
                      placeholder="请输入权限模板"
                      clearable
                      :style="{ width: '100%' }"
                    >
                      <el-option
                        v-for="(item, index) in field101Options"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                        :disabled="item.disabled"
                      ></el-option>
                    </el-select>
          </el-form-item>

          <!-- <el-form-item label="密码" prop="password">
            <el-input
              size="small"
              v-model="revise.password"
              auto-complete="off"
              placeholder="请输入密码"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item> -->

          <el-form-item label="营业执照" prop="businessUrl">
            <el-upload
              class="upload-demo"
              :action="actionUrl()"
              :on-change="handleChange"
              :on-remove="handleRemove"
              :file-list="fileList"
              :auto-upload="false"
              :limit="1"
              accept=".jpg,.png,.jpeg,JPG,JPEG"
              list-type="picture"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>

          <el-form-item label="营业地址" prop="password5">
            <el-input
              size="small"
              maxlength="100"
              v-model="revise.two"
              auto-complete="off"
              placeholder="请输入营业地址"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
          <el-form-item label="营业执照编号" prop="businessNum">
            <el-input
              size="small"
              maxlength="50"
              v-model="revise.businessNum"
              auto-complete="off"
              placeholder="请输入营业执照编号"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
          <el-form-item label="法人" prop="password7">
            <el-input
              size="small"
              v-model="revise.legalPerson"
              auto-complete="off"
              maxlength="10"
              placeholder="请输入法人"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="editFormVisible = false"
            >取消</el-button
          >
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            @click="edit('ruleForm')"
            >确定</el-button
          >
        </div>
      </el-dialog>

      <!-- ..添加弹窗 -->
      <el-dialog
        title="新增"
        :visible.sync="addVisible"
        width="30%"
      
      >
        <el-form
          label-width="150px"
          :model="revise"
          :rules="reviseRules"
          ref="ruleForm"
        >
          <el-form-item label="租户名称" prop="nickName">
            <el-input
              size="small"
              maxlength="10"
              v-model="revise.nickName"
              auto-complete="off"
              placeholder="请输入租户名称"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="账号" prop="userName">
            <el-input
              size="small"
              maxlength="20"
              v-model="revise.userName"
              auto-complete="off"
              placeholder="请输入账号"
             
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="手机号" prop="phonenumber">
            <el-input
              size="small"
              maxlength="11"
              v-model.number="revise.phonenumber"
              auto-complete="off"
              placeholder="请输入手机号"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="可创建项目个数" prop="proNum">
            <el-input
              size="small"
              maxlength="3"
              v-model="revise.proNum"
              auto-complete="off"
              placeholder="请输入可创建项目个数"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>

          <el-form-item label="到期时间" prop="expirationTime">
            <el-date-picker
              v-model="revise.expirationTime"
              type="date"
              value-format='yyyy-MM-dd'
              placeholder="选择日期"
              :picker-options="pickerOptions0"
            >
            </el-date-picker>
          </el-form-item>

          <!-- <el-form-item label="密码" prop="password">
            <el-input
              size="small"
              v-model="revise.password"
              auto-complete="off"
              placeholder="请输入密码"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item> -->

          <el-form-item label="权限模板" prop="Authority">
             <el-select
                      v-model="revise.Authority"
                      placeholder="请输入权限模板"
                      clearable
                      :style="{ width: '100%' }"
                    >
                      <el-option
                        v-for="(item, index) in AuthorityData"
                        :key="index"
                        :label="item.name"
                        :value="item.id"
                        :disabled="item.disabled"
                      ></el-option>
                    </el-select>
          </el-form-item>

            <el-form-item label="状态" prop="state">
             <el-select
                      v-model="revise.state"
                      placeholder="请输入权限模板"
                      clearable
                      :style="{ width: '100%' }"
                    >
                      <el-option
                        v-for="(item, index) in field101Options"
                        :key="index"
                        :label="item.label"
                        :value="item.value"
                      ></el-option>
                    </el-select>
          </el-form-item>

          <el-form-item label="营业执照" prop="businessUrl">
            <el-upload
              class="upload-demo"
              :action="actionUrl()"
              :on-change="handleChange"
              :on-remove="handleRemove"
              :file-list="fileList"
              :auto-upload="false"
              :limit="1"
              accept=".jpg,.png,.jpeg,JPG,JPEG"
              list-type="picture"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>

          <el-form-item label="营业地址" prop="password5">
            <el-input
              size="small"
              maxlength="100"
              v-model="revise.two"
              placeholder="请输入营业地址"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
          <el-form-item label="营业执照编号" prop="businessNum">
            <el-input
              size="small"
              v-model="revise.businessNum"
              placeholder="请输入营业执照编号"
              maxlength="50"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
          <el-form-item label="法人" prop="password7">
            <el-input
              size="small"
              v-model="revise.legalPerson"
              placeholder="请输入法人"
              maxlength="10"
              onkeyup="this.value=this.value.replace(/[, ]/g,'')"
            ></el-input>
          </el-form-item>
        </el-form>

        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="addVisible = false">取消</el-button>
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            @click="save('ruleForm')"
            >确定</el-button
          >
        </div>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// import { registeraAdd} from "@/api/monet.js";
import {
  listTemplate
} from "@/api/system/template";
import { addUser, selectByTenantList, updateUser } from "@/api/base/index.js";
import { upload,getSetup } from "@/api/system/index.js";
export default {
  data() {
    return {
      //获取基础设置的可创建项目个数
      projectNum:"",
        pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now() - 8.64e6;
        },
      },
      pickerOptions0: {
          disabledDate(time) {
            return time.getTime() < Date.now() - 8.64e7;
          }
        },  
      // 权限模板下拉参数
      AuthorityData:[

      ],
      // 上传营业执照
      fileList: [],
      // 营业执照地址
      businessUrl: "",
      //  搜索状态
      field101Options: [
        {
          label: "停用",
          value: 1,
        },
        {
          label: "正常",
          value: 0,
        },
        {
          label: "禁用",
          value: 2,
        },
      ],

      // ..编辑界面的表单参数
      revise: {
        businessNum: "", //营业执照编号
        businessUr: "", //营业执照网络地址
        legalPerson: "", //法人
        two: "", //营业地址
        Authority:'', //权限模板
        userName: "", //登陆名称 //账号
        nickName: "", //用户名称   租户名称
        phonenumber: "", //手机号码
        password: "", //密码
        expirationTime: "", //到期时间
        proNum: "", //可创建项目数
        userId:"",
        reId:"",
        state:0,   //状态
      },
      // 表单校验
      reviseRules: {
        nickName: [
          { required: true, message: "租户名称不能为空", trigger: "blur" },
        ],
        proNum: [
          { required: true, message: "可创建项目数不能为空", trigger: "change" },
          {
          pattern: /^\d+$/ ,
          message: '格式错误',
          trigger: 'change'
        }
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
        expirationTime: [
          { required: true, message: "到期时间不能为空", trigger: "blur" },
        ],
        userName: [
          { required: true, message: "账号不能为空", trigger: "blur" },
        ],
        phonenumber: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {
          pattern: /^[1][3,4,5,7,8,9][0-9]{9}$/ ,
          message: '格式错误',
          trigger: 'change'
        }
        ],
        Authority: [
          { required: true, message: "权限模板不能为空", trigger: "blur" },
        ],
        state: [
          { required: true, message: "状态不能为空", trigger: "blur" },
        ],
      },
      editFormVisible: false,
      // 添加弹窗
      addVisible: false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      // ids: [],
      // 非单个禁用
      // single: true,
      // 非多个禁用
      // multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 角色表格数据
      roleList: [
        // {
        //   userName: "1",
        //   idCard: "4108231994554541515",
        // },
      ],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 是否显示弹出层（数据权限）
      openDataScope: false,
      menuExpand: false,
      menuNodeAll: false,
      deptExpand: true,
      deptNodeAll: false,
      // 日期范围
      dateRange: [],
      // 状态数据字典
      statusOptions: [],
      // 数据范围选项
      dataScopeOptions: [
        {
          value: "1",
          label: "全部数据权限",
        },
        {
          value: "2",
          label: "自定数据权限",
        },
        {
          value: "3",
          label: "本部门数据权限",
        },
        {
          value: "4",
          label: "本部门及以下数据权限",
        },
        {
          value: "5",
          label: "仅本人数据权限",
        },
      ],
      // 菜单列表
      menuOptions: [],
      // 部门列表
      deptOptions: [],
      // 查询参数
      queryParams: {
        nickName: "",
        stateUser: "",
        phoneNumber: "",
        pageNum: 1,
        pageSize: 10,
        roleName: undefined,
        roleKey: undefined,
        status: undefined,
        cTime:[],
        tempName:"",
      },
      // 表单参数
      form: {},
      defaultProps: {
        children: "children",
        label: "label",
      },

      // 用户ID
      userId: "",
    };
  },
  created() {
    this.loading = false;
    const userID = sessionStorage.getItem("userID");
    this.userId = userID - 0;
    this.getList();
  },
  methods: {
     async getList() {
            const pz = await getSetup();
          console.log(pz, "获取基础设置");
            this.projectNum= pz.data.projectNum;


        console.log(this.queryParams,'搜索')
      let AuthorityParam={
        pageNum:this.queryParams.pageNum,
        pageSize:this.queryParams.pageSize
      };
     
      
      //获取权限模板
        listTemplate(AuthorityParam).then((response) => {
        console.log(response,'权限模板')
        this.AuthorityData=response.rows;
        this.revise.Authority=response.rows[0].id;
      });

      if(this.queryParams.cTime==null){
        this.queryParams.cTime=[];
      }
      let param = {
        nickName: this.queryParams.nickName,
        phoneNumber: this.queryParams.phoneNumber,
        stateUser: this.queryParams.stateUser,
        pageNum:this.queryParams.pageNum,
        pageSize:this.queryParams.pageSize,
        cTime:this.queryParams.cTime[0],
        eTime:this.queryParams.cTime[1],
        tempId:this.queryParams.tempName,
      };
        
      console.log(param, "搜索数据");

      const data  = await selectByTenantList(param);
      console.log(data, "获取数据列表");
      // one  实名状态0实名1未实名
      this.roleList = data.data.list;
      this.total = data.data.total;

      // this.loading = true;
    },
    // 新增按钮
   async addData() {
      this.addVisible = true;
      this.revise.businessNum=''; //营业执照编号
      this.revise.businessUr=''; //营业执照网络地址
      this.revise.legalPerson=''; //法人
      this.revise.two='';  //营业地址
      // this.revise.Authority=''; //权限模板
      this.revise.userName=''; //登陆名称 //账号
      this.revise.nickName='';  //用户名称   租户名称
      this.revise.phonenumber=''; //手机号码
      this.revise.password='';  //密码
      this.revise.expirationTime='';  //到期时间
      this.revise.proNum='';   //可创建项目数
      this.revise.userId='';  
      this.revise.reId=''; 

        let AuthorityParam={
        pageNum:this.queryParams.pageNum,
        pageSize:this.queryParams.pageSize
      };
          listTemplate(AuthorityParam).then((response) => {
            console.log(response,'4444')
            this.AuthorityData=response.data.list;
        this.revise.Authority=response.rows[0].id;
      });
      this.revise.state=0;
      this.fileList = [];
    },
    actionUrl() {
      return "";
    },
    // 搜索按钮
    searchButton() {
      this.getList();
      console.log(this.queryParams, "搜索按钮");
    },
    // 删除按钮
    deleteUser(index, scope) {
      console.log(index, scope, "删除");
    },
    // 营业执照上传 // 取消图片的函数
    handleRemove(file, fileList) {
      console.log(file, fileList);
    },

    handleChange(file, fileList) {
      this.fileList.push(file);

      console.log(file, "1111");

      let formData = new FormData();

      // formData.append("avatarfile", file.raw);
      formData.append("file", file.raw);

      console.log(this.fileList, "333");

      upload(formData).then((data) => {
        console.log(data, "222");
        this.businessUrl = data.fileName;
        // this.form.partnerLogo = data.imgUrl;
      });
    },

    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${
          files.length + fileList.length
        } 个文件`
      );
    },

    // ..新增按钮里面的保存
    save(formName) {
      // console.log( this.revise.expirationTime,'333')
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.revise.proNum>this.projectNum) {
            this.$message({
              message: `创建项目个数不可大于${this.projectNum}个`,
              type: "warning",
            });
          } else {
            let param = {
              realnameUser: {
                businessNum: this.revise.businessNum, //营业执照编号
                businessUrl: this.businessUrl, //营业执照网络地址
                legalPerson: this.revise.legalPerson, //法人
                two: this.revise.two, //营业地址
              },
              sysUser: {
                userName: this.revise.userName, //登陆名称 //账号
                nickName: this.revise.nickName, //用户名称   租户名称
                phonenumber: this.revise.phonenumber, //手机号码
                password: this.revise.password, //密码
                expirationTime: this.revise.expirationTime, //到期时间
                proNum: this.revise.proNum, //可创建项目数
                tempId: this.revise.Authority, //权限模板
                status: this.revise.state, //状态
              },
            };

            addUser(param).then((res) => {
              console.log(res, "结果5555555555555");
              if ((res.code = 200)) {
                this.$message({
                  type: "success",
                  message: "新增成功！",
                });
                this.getList();
                this.addVisible = false;
              } else {
                this.$message.error("新增失败！");
              }
            });
          }

          // realnameUser:{
          //   businessNum, //营业执照编号
          //   businessUrl,   //营业执照网络地址
          //   legalPerson, //法人
          //   two,  //营业地址
          //   },
          //   sysUser:{
          //     userName, //登陆名称 //账号
          //     nickName, //用户名称   租户名称
          //     phonenumber, //手机号码
          //     password, //密码
          //     expirationTime,   //到期时间
          //     proNum,   //可创建项目数

          //   }
        } else {
          return false;
        }
      });
    },
    // ..编辑按钮里面的保存
    edit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
           if (this.revise.proNum>this.projectNum) {
            this.$message({
              message: `创建项目个数不可大于${this.projectNum}个`,
              type: "warning",
            });
          }else{
             let param = {
        realnameUser: {
          businessNum: this.revise.businessNum, //营业执照编号
          // businessUrl:this.revise.businessUrl, //营业执照网络地址
          legalPerson: this.revise.legalPerson, //法人
          two: this.revise.two, //营业地址
          reId:this.revise.reId
        },
        sysUser: {
          userName: this.revise.userName, //登陆名称 //账号
          nickName: this.revise.nickName, //用户名称   租户名称
          phonenumber: this.revise.phonenumber, //手机号码
          // password: this.revise.password, //密码
          expirationTime: this.revise.expirationTime, //到期时间
          proNum: this.revise.proNum, //可创建项目数
          userId:this.revise.userId,
          tempId: this.revise.Authority, //权限模板
          status: this.revise.state, //状态
        },
      };
        updateUser(param).then((res) => {
        console.log(res, "编辑结果5555555555555");
        if(res.code=200){
           this.$message({
                  type: "success",
                  message: "编辑成功！",
                });
                 this.getList();
            this.editFormVisible=false;
        }else{
           this.$message.error('编辑失败');
        }
      });
          }
            
    
          // realnameUser:{
          //   businessNum, //营业执照编号
          //   businessUrl,   //营业执照网络地址
          //   legalPerson, //法人
          //   two,  //营业地址
          //   },
          //   sysUser:{
          //     userName, //登陆名称 //账号
          //     nickName, //用户名称   租户名称
          //     phonenumber, //手机号码
          //     password, //密码
          //     expirationTime,   //到期时间
          //     proNum,   //可创建项目数
          //   }
      
       
        } else {
          return false;
        }
      });
    },
    //..显示编辑界面
    handleEdit: function (index, row) {
      this.editFormVisible = true;
      console.log(row, "点击编辑按钮");
      this.revise.userId=row.userId;
      this.revise.nickName = row.nickName;
      this.revise.reId = row.reId;
      this.revise.userName = row.userName;
      this.revise.phonenumber = row.phoneNumber;
      this.revise.proNum = row.proNum;
      this.revise.expirationTime = row.eTime;
      this.revise.password = row.password;
      this.revise.Authority = row.tempId;
      this.revise.state = row.stateUser;
      // this.revise.two = row.two;
        

      this.revise.businessNum = row.businessNum;
      this.revise.legalPerson = row.legalPerson;

      this.fileList[0].url = this.businessUrl||''; //营业执照图片地址
      this.fileList[0].name = this.businessNum||''; //营业执照图片地址
      console.log(this.fileList,'3333')

      // realnameUser:{
      //   businessNum, //营业执照编号
      //   businessUr,   //营业执照网络地址
      //   legalPerson, //法人
      //   two,  //营业地址
      //   },
      //   sysUser:{
      //     userName, //登陆名称 //账号
      //     nickName, //用户名称   租户名称
      //     phonenumber, //手机号码
      //     password, //密码
      //     expirationTime,   //到期时间
      //     proNum,   //可创建项目数
      //   }
    },
   
    /** 查询菜单树结构 */
    getMenuTreeselect() {
      menuTreeselect().then((response) => {
        this.menuOptions = response.data;
      });
    },
    /** 查询部门树结构 */
    getDeptTreeselect() {
      deptTreeselect().then((response) => {
        this.deptOptions = response.data;
      });
    },

    // 角色状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$confirm(
        '确认要"' + text + '""' + row.roleName + '"角色吗?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return changeRoleStatus(row.roleId, row.status);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消按钮（数据权限）
    cancelDataScope() {
      this.openDataScope = false;
      this.reset();
    },
    // 表单重置
    reset() {
      if (this.$refs.menu != undefined) {
        this.$refs.menu.setCheckedKeys([]);
      }
      (this.menuExpand = false),
        (this.menuNodeAll = false),
        (this.deptExpand = true),
        (this.deptNodeAll = false),
        (this.form = {
          roleId: undefined,
          roleName: undefined,
          roleKey: undefined,
          roleSort: 0,
          status: "0",
          menuIds: [],
          deptIds: [],
          menuCheckStrictly: true,
          deptCheckStrictly: true,
          remark: undefined,
        });
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.roleId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleDataScope":
          this.handleDataScope(row);
          break;
        case "handleAuthUser":
          this.handleAuthUser(row);
          break;
        default:
          break;
      }
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getMenuTreeselect();
      this.open = true;
      this.title = "添加角色";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const roleId = row.roleId || this.ids;
      const roleMenu = this.getRoleMenuTreeselect(roleId);
      getRole(roleId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.$nextTick(() => {
          roleMenu.then((res) => {
            let checkedKeys = res.checkedKeys;
            checkedKeys.forEach((v) => {
              this.$nextTick(() => {
                this.$refs.menu.setChecked(v, true, false);
              });
            });
          });
        });
        this.title = "修改角色";
      });
    },
    /** 选择角色权限范围触发 */
    dataScopeSelectChange(value) {
      if (value !== "2") {
        this.$refs.dept.setCheckedKeys([]);
      }
    },
    /** 分配数据权限操作 */
    handleDataScope(row) {
      this.reset();
      const roleDeptTreeselect = this.getRoleDeptTreeselect(row.roleId);
      getRole(row.roleId).then((response) => {
        this.form = response.data;
        this.openDataScope = true;
        this.$nextTick(() => {
          roleDeptTreeselect.then((res) => {
            this.$refs.dept.setCheckedKeys(res.checkedKeys);
          });
        });
        this.title = "分配数据权限";
      });
    },
    /** 分配用户操作 */
    handleAuthUser: function (row) {
      const roleId = row.roleId;
      this.$router.push("/system/role-auth/user/" + roleId);
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.roleId != undefined) {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            updateRole(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            this.form.menuIds = this.getMenuAllCheckedKeys();
            addRole(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交按钮（数据权限） */
    submitDataScope: function () {
      if (this.form.roleId != undefined) {
        this.form.deptIds = this.getDeptAllCheckedKeys();
        dataScope(this.form).then((response) => {
          this.msgSuccess("修改成功");
          this.openDataScope = false;
          this.getList();
        });
      }
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const roleIds = row.roleId || this.ids;
      this.$confirm(
        '是否确认删除角色编号为"' + roleIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delRole(roleIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      console.log(queryParams, "000");
      this.$confirm("是否确认导出所有角色数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          //  console.log(exportRole(queryParams),'001')
          // return exportRole(queryParams);
        })
        .then((response) => {
          console.log(response, "1111");
          // this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>

<style scoped lang="scss">
.servers {
  padding: 20px;
  overflow: hidden;
  height: auto;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.3);
  .title {
    height: 50px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    img {
      height: 30px;
      margin-right: 10px;
    }
  }
  .sousuoBox {
    margin-top: 20px;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    .el-form-item {
      margin-right: 50px;
    }
  }
}
</style>

